package leetcode;

/**
 * @author Liangyaoyun
 */
public class leetCode167 {
    public int[] twoSum(int[] numbers, int target) {
        int[] res = new int[2];
        int left = 0;
        int right = numbers.length - 1;

        while (left < right) {
            if (target==numbers[left]+numbers[right]){
                res[0] = left + 1;
                res[1] = right + 1;
                return res;
            }else if (target<numbers[left]+numbers[right]){
                right--;
            }else {
                left++;
            }
        }
        return res;
    }

    public static void main(String[] args) {
        int[] nums = new int[]{1, 3, 4, 4};
        int target = 8;
        leetCode167 leetCode167 = new leetCode167();
        System.out.println(leetCode167.twoSum(nums, target));
    }
}
